package com.upcode.weighing.oauthserver.controller;

import com.upcode.weighing.base.controller.BaseController;
import com.upcode.weighing.oauthserver.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 *
 * @author zyw
 * @date 2018/2/05
 */
@RestController
public class AuthController extends BaseController {

   @Autowired
   private AuthService authService;

    @Autowired
    @Qualifier("consumerTokenServices")
    private ConsumerTokenServices consumerTokenServices;


    @GetMapping("/user")
    public Principal user(Principal user){
        return user;
    }



    //退出登录
    @GetMapping("/logout2")
    public void logOut(String username){
         authService.logOut(username);
    }

    @GetMapping("/removeToken")
    public Boolean removeToken(String accessToken){
        return consumerTokenServices.revokeToken(accessToken);
    }

}
